package com.augn.service.impl;

import com.augn.entity.Address;
import com.augn.entity.Collection;
import com.augn.entity.Result;
import com.augn.mapper.CollectionMapper;
import com.augn.service.ICollectionService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author augn
 * @since 2022-09-22
 */
@Service
public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, Collection> implements ICollectionService {

    @Autowired
    private CollectionMapper mapper;

    //新增一件商品收藏
    @Override
    public Result<?> insertOneCollection(Collection collection) {
        int insert = mapper.insert(collection);
        if(insert==0){
            return Result.error("-1","新增失败");
        } else{
            return Result.success(insert);
        }
    }

    //删除一件商品收藏
    @Override
    public Result<?> deleteOneCollection(Integer id) {
        int delete = mapper.deleteById(id);
        if(delete==0){
            return Result.error("-1","删除失败");
        } else{
            return Result.success(delete);
        }
    }

    @Override
    public Result<?> getPartCollection(Integer id) {
        QueryWrapper<Collection> wrapper= new QueryWrapper<>();
        wrapper.eq("user_id",id);
        List<Collection> collectionList = mapper.selectList(wrapper);
        if(collectionList.isEmpty()){
            return Result.error("-1","暂无地址");
        } else{
            return Result.success(collectionList);
        }
    }
}
